package ViewPackage;

import java.awt.Color;
import java.awt.Graphics;

public class Bullet {
	
	public static int szam=0;
	public int mySzam;
	//Ez jelzi hogy meg ki kell rajzolni
	private boolean valid=true;
	
	private int x,y;
	private int delay,delaySteps;
	private int targetX,targetY;
	

	GameView gv;
	
	public Bullet(int x,int y, int targetX, int targetY,int targetMoveDelay,GameView gv){
		mySzam=szam;
		szam++;
		this.x=x;
		this.y=y;
		delay=targetMoveDelay;
		this.targetX=targetX;
		this.targetY=targetY;
		this.delay=targetMoveDelay;
		this.delaySteps=0;
		this.gv=gv;
	}
	
	public void update(Graphics g){
		
		if(!valid)System.out.println("en az "+mySzam+"Bullet vok de nem toroltek!!");
		
		delaySteps++;
		if(delay<=delaySteps){
			this.invalidate();
			gv.removeBullet(this);
		}
		else draw(g);
	}
	
	//"lezer" rajzolasa
	public void draw(Graphics g){
		
		if(valid){
			//fekete vonal rajzoalasa
			g.setColor(Color.black);
			g.drawLine(x,y,targetX,targetY);
		}
		else System.out.println("Invalid Bullet draw");		
	}
	
	//atallitas nem kirajzolandova
	public void invalidate(){
		this.valid=false;
	}
}
